package com.itheima.app.controller;

import cn.hutool.core.date.DateUtil;
import com.itheima.app.manager.MakeFriendManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
public class MakeFriendController {

    @Autowired
    MakeFriendManager makeFriendManager;

    //今日佳人
    @GetMapping("/tanhua/todayBest")
    public ResponseEntity findTodayBest(){
        return makeFriendManager.findTodayBest();
    }

    //推荐列表
    @GetMapping("/tanhua/recommendation")
    public ResponseEntity findRecommendUserByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize ){
        return makeFriendManager.findRecommendUserByPage(pageNum,pageSize);
    }

    //推荐用户详情
    @GetMapping("/tanhua/{recommendUserId}/personalInfo")
    public ResponseEntity findPersonalInfo(@PathVariable Long recommendUserId){
        return makeFriendManager.findPersonalInfo(recommendUserId);
    }

    //是否已经喜欢
    @GetMapping("/users/{recommendUserId}/alreadyLove")
    public ResponseEntity findAlreadyLove(@PathVariable Long recommendUserId){
        //TODO 项目实战的时候需要完成
        return ResponseEntity.ok(false);
    }

    //最近访客
    @GetMapping("/movements/visitors")
    public ResponseEntity findVisitorsTop5(){
        return makeFriendManager.findVisitorsTop5();
    }

    //上报地址位置
    @PostMapping("/baidu/location")
    public ResponseEntity saveUserLocation(@RequestBody Map<String,String> map){
        System.out.println(DateUtil.formatDateTime(new Date())+"-上报地址位置-"+map);

        Double longitude = Double.parseDouble(map.get("longitude"));//经度
        Double latitude = Double.parseDouble(map.get("latitude"));//纬度
        String addrStr = map.get("addrStr");

        return makeFriendManager.saveUserLocation(longitude,latitude,addrStr);
    }

    //搜附近
    @GetMapping("/tanhua/search")
    public ResponseEntity searchNear(String gender,Long distance){
        return makeFriendManager.searchNear( gender, distance);
    }

    //查看陌生人问题
    @GetMapping("/tanhua/strangerQuestions")
    public ResponseEntity findStrangerQuestions(@RequestParam("userId") Long recommendUserId){
        return makeFriendManager.findStrangerQuestions(recommendUserId);
    }
}
